package java8.methodReference;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

public class Car {
	public static interface MySupplier<T>{
		T get();
	}
	public static Car create(Supplier<Car> supplier) {
		return supplier.get();
	}
	public static Car create1(MySupplier<Car> supplier) {
		return supplier.get();
	}
	public static void collide(Car car) {
		System.out.println("Collided " + car.toString());
	}
	public void follow(Car another) {
		 System.out.println("Following the " + another.toString());
	}
	public void repair() {
		System.out.println("Repaired " + this.toString());
	}
	public static void main(String[] args) {
		Car car = create(Car::new);
		Car car1 = create1(Car::new);
		List<Car> cars = Arrays.asList(car,car1);
		//Class::static_method
		cars.forEach(Car::collide);
		//instance::method
		cars.forEach(car1::follow);
		cars.forEach(car::follow);
		//Class::method
		cars.forEach(Car::repair);
	}
}
